package com.example.DataSource.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.DataSource.entity.answer_replies;
import com.example.DataSource.serviceImpl.answerServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/ljkDemo/answer")
public class answerController {
    @Autowired
    private com.example.DataSource.Mapper.answerMapper answerMapper;
    @Autowired
    private answerServiceImpl answerService;

    // 定义一个 GET 请求的接口，用于获取分页数据
    @GetMapping("/getall")
    public IPage<answer_replies> getAll(int current, int size) {
        // 创建一个分页对象，指定当前页码和每页大小
        Page<answer_replies> page = new Page<>(current, size);
        // 调用 Service 层的方法获取分页数据
        return answerService.getAnswerPage(page);
    }

    @GetMapping("/deleteInfo")
    public void deleted(String id){
//        System.out.println("删除的是"+id);
        answerService.removeById(id);
    }

    @GetMapping("/search")
    public IPage<answer_replies> search(int current,int size,String searchInfo){
        // 创建一个分页对象，指定当前页码和每页大小
        Page<answer_replies> page = new Page<>(current, size);
        // 调用 Service 层的方法获取分页数据
        return answerService.getAnswerPageSearch(page,searchInfo);
    }


}
